<?php

namespace App\Http\Controllers\Admin;

use App\Model\Order;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex(Request $request)
    {
        $request = $request -> all();
        //
        $data = Order::paginate(10);
        foreach($data as $k=>$v){
            $data[$k]['user'] = Order::find($v['oid'])->user()->first();

        }
        ///dd($data);
        return view('admin.order.index',['data'=>$data,'request'=>$request]);
    }


    public function getDelete($id)
    {
        $res = Order::find($id)->delete();
        if($res){
            return redirect('/admin/order')->with('success','删除成功');
        }else{
            return back()->with('error','添加失败');
        }
    }

    public function getInfo(Request $request)
    {
        $a = $request->all();
       $info = Order::where('oid',$a['oid'])->get();
        // 1 查询出当前分类下的所有文章

//        定义一个空字符串来接收每行的文章记录
        $str =' <center><table style="text-algin:center" border="0 solid #ccc" width="605px" height="90px"><tr><th class="tc">ID</th><th>收货人</th><th>收货地址</th><th>收货人电话</th><th>货品总价</th>';

        foreach($info as $k=>$v){
            $str.= "<tr >
               <th >{$v->oid}</th>
               <th>{$v->o_name}</th>
               <th>{$v->oaddress}</th>
               <th>{$v->o_phone}</th>
               <th>{$v->o_prices}</th>
              
              </tr>";
        }
        $str.= '</table>';
        // 2 将查询后的结果变成一个字符串格式的表格

        return $str;
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
